home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / plot / __plr2__.m < prev    next >
Text File  |  1996-07-12  |  3KB  |  112 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## Author: jwe
  21.  
  22. function __plr2__ (theta, rho, fmt)
  23.  
  24.   if (nargin != 3)
  25.     usage ("__plr2__ (theta, rho, fmt)");
  26.   endif
  27.  
  28.   if (any (imag (theta)))
  29.     theta = real (theta);
  30.   endif
  31.  
  32.   if (any (imag (rho)))
  33.     rho = real (rho);
  34.   endif
  35.  
  36.   if (is_scalar (theta))
  37.     if (is_scalar (rho))
  38.       x = rho * cos (theta);
  39.       y = rho * sin (theta);
  40.       __plt2ss__ (x, y, fmt);
  41.     endif
  42.   elseif (is_vector (theta))
  43.     if (is_vector (rho))
  44.       if (length (theta) != length (rho))
  45.     error ("polar: vector lengths must match");
  46.       endif
  47.       if (rows (rho) == 1)
  48.     rho = rho';
  49.       endif
  50.       if (rows (theta) == 1)
  51.     theta = theta';
  52.       endif
  53.       x = rho .* cos (theta);
  54.       y = rho .* sin (theta);
  55.       __plt2vv__ (x, y, fmt);
  56.     elseif (is_matrix (rho))
  57.       [t_nr, t_nc] = size (theta);
  58.       if (t_nr == 1)
  59.     theta = theta';
  60.     tmp = t_nr;
  61.     t_nr = t_nc;
  62.     t_nc = tmp;
  63.       endif
  64.       [r_nr, r_nc] = size (rho);
  65.       if (t_nr != r_nr)
  66.     rho = rho';
  67.     tmp = r_nr;
  68.     r_nr = r_nc;
  69.     r_nc = tmp;
  70.       endif
  71.       if (t_nr != r_nr)
  72.     error ("polar: vector and matrix sizes must match");
  73.       endif
  74.       x = diag (cos (theta)) * rho;
  75.       y = diag (sin (theta)) * rho;
  76.       __plt2vm__ (x, y, fmt);
  77.     endif
  78.   elseif (is_matrix (theta))
  79.     if (is_vector (rho))
  80.       [r_nr, r_nc] = size (rho);
  81.       if (r_nr == 1)
  82.     rho = rho';
  83.     tmp = r_nr;
  84.     r_nr = r_nc;
  85.     r_nc = tmp;
  86.       endif
  87.       [t_nr, t_nc] = size (theta);
  88.       if (r_nr != t_nr)
  89.     theta = theta';
  90.     tmp = t_nr;
  91.     t_nr = t_nc;
  92.     t_nc = tmp;
  93.       endif
  94.       if (r_nr != t_nr)
  95.     error ("polar: vector and matrix sizes must match");
  96.       endif
  97.       diag_r = diag (r);
  98.       x = diag_r * cos (theta);
  99.       y = diag_r * sin (theta);
  100.       __plt2mv__ (x, y, fmt);
  101.     elseif (is_matrix (rho))
  102.       if (size (rho) != size (theta))
  103.     error ("polar: matrix dimensions must match");
  104.       endif
  105.       x = rho .* cos (theta);
  106.       y = rho .* sin (theta);
  107.       __plt2mm__ (x, y, fmt);
  108.     endif
  109.   endif
  110.  
  111. endfunction
  112.